package com.binc1.day1;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/*** @Title: dongtai
 * @Description:
 * @Auther: binC
 * @Version: 1.0
 * @create 2020/10/22 21:03 
 */
public class MyProxy implements InvocationHandler {
    //被代理类
    private Object target;

    public void setTarget(Object target) {
        this.target = target;
    }
    //生成代理类
    public Object getProxy(){
        return Proxy.newProxyInstance(this.getClass().getClassLoader(), target.getClass().getInterfaces(), this);
    }
    //处理代理实例
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("代理前做一些操作");
        return method.invoke(target,args);
    }
}
